package com.tianqingwl.gsystem.resources.controller;

import com.tianqingwl.gsystem.common.enumeration.SysConfigConstants;
import com.tianqingwl.gsystem.resources.service.SysConfigService;
import com.tianqingwl.gsystem.resources.service.SysPermissionService;
import com.tianqingwl.gsystem.resources.vo.MenuInfoVo;
import com.tianqingwl.gsystem.sysuser.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 后台 json 数据
 */
@RequestMapping("/manage")
@RestController
public class ManageVoController {

    @Autowired
    private SysPermissionService permissionService;
    @Autowired
    private SysConfigService sysConfigService;

    @GetMapping("/index/init")
    public Object indexInit(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        SysUser user = (SysUser) authentication.getPrincipal();

        Map result = new HashMap<>();
        //默认页
        //HomeInfoVo homeInfo = new HomeInfoVo();
        Map mapByGroup = sysConfigService.getMapByGroup(SysConfigConstants.Group.init_home_page);
        result.put("homeInfo",mapByGroup);
        //加载站点配置
        //LogoInfoVo logoInfo = new LogoInfoVo();
        Map site_logo_info = sysConfigService.getMapByGroup(SysConfigConstants.Group.site_logo_info);
        result.put("logoInfo",site_logo_info);
        //加载当前用户权限菜单
        List<MenuInfoVo> menuInfoList =permissionService.getUserMenuInfoVo(user.getUsername());
        result.put("menuInfo",menuInfoList);
        return result;
    }
}
